
         global
         include \powerc\source\libdef.asm
         dref  myss
         dref  stack
         lref  suspending
         dref  olddisk
         dref  oldvideo
         dref  diskflag
         lref  videoflag
         dref  dosbusy
         fref  $$MAXS
         lfref popup_tsr
         dref  scancode
         dref  keymask
         dref  popflg
         dref  oldkb
         dref  oldtimer
         dref  old28
         dorg  $
         ddef  running
intss    DW    0
intsp    DW    0
running  DW    0
         endglobal
         org   $
         idt   getsp
         def   getsp
getsp    equ   $
         mov   ax,sp
         retfar
         idt   keyhit
         def   keyhit
keyhit   equ   $
         mov   ah,1
         int   >16
         mov   ah,1
         jnz   keyret
         int   >28
         mov   ax,0
keyret   retfar
         idt   dores
         def   dores
dores    equ   $
         cmp   [suspending],0
         jne   resret
         mov   [running],1
         cli
         mov   [intss],ss
         mov   [intsp],sp
         mov   ss,[myss]
         mov   sp,[stack]
         sti
         callfar popup_tsr
         cli
         mov   ss,[intss]
         mov   sp,[intsp]
         sti
         mov   [running],0
resret   retfar
         idt newdisk
         def newdisk
newdisk  equ $
         push ds
         push bp
         segcs
         mov bp,[dgroup]
         mov ds,bp
         inc [diskflag]
         pushf
         segds
         callseg [olddisk]
         dec [diskflag]
         pop bp
         pop ds
         retseg 2
         idt newvideo
         def newvideo
newvideo push ds
         push bp
         segcs
         mov bp,[dgroup]
         mov ds,bp
         inc [videoflag]
         pop bp
         pushf
         segds
         callseg [oldvideo]
         dec [videoflag]
         pop ds
         iret
         idt vpoke
         def vpoke
vpoke    equ $
         push bp
         mov bp,sp
         push di
         push es
         mov cx,[bp][%PARM1]
         mov es,cx
         mov di,[bp][%PARM2]
         cmp cx,45056
         jz mono1
         mov dx,986
loop1    in al,dx
         test al,1
         jnz loop1
loop2    in al,dx
         test al,1
         jz loop2
mono1    mov ax,[bp][%PARM3]
         stosw
         pop es
         pop di
         pop bp
         retfar
         idt vpeek
         def vpeek
vpeek    equ $
         push bp
         mov bp,sp
         push si
         push ds
         mov si,[bp][%PARM2]
         mov cx,[bp][%PARM1]
         mov ds,cx
         cmp cx,45056
         jz mono2
         mov dx,986
loop3    in al,dx
         test al,1
         jnz loop3
loop4    in al,dx
         test al,1
         jz loop4
mono2    lodsw
         pop ds
         pop si
         pop bp
         retfar
dgroup   equ $+3
         callfar $$MAXS
         def newkb
newkb    equ $
         push ax
         push bx
         push cx
         push ds
         segcs
         mov  cx,[dgroup]
         mov  ds,cx
         mov  bh,[keymask]
         xor  ax,ax
         mov  ds,ax
         mov  ah,[>417]
         mov  ds,cx
         and  ah,bh
         cmp  ah,bh
         jnz  exold
         mov  bl,[scancode]
         cmp  bl,0
         jz   exold
         in   al,>60
         cmp  al,bl
         jnz  exold
         cli
         in   al,>61
         mov  ah,al
         or   al,>80
         out  >61,al
         mov  al,ah
         out  >61,al
         mov  al,>20
         out  >20,al
         sti
         mov  ax,[running]
         cmp  ax,0
         jnz  skipex
         mov  [popflg],1
         jmp  skipex
exold    pushf
         segds
         callseg [oldkb]
skipex   pop  ds
         pop  cx
         pop  bx
         pop  ax
         iret
         def newtimer
newtimer equ $
         push ax
         push bx
         push cx
         push ds
         push es
         segcs
         mov  cx,[dgroup]
         mov  ds,cx
         pushf
         segds
         callseg [oldtimer]
         mov  bh,[scancode]    ; if !scancode
         cmp  bh,0
         jnz  if2
         mov  bh,[suspending]     ; if !suspending
         cmp  bh,0
         jnz  if2
         mov  bh,[keymask]          ; key?
         xor  ax,ax
         mov  ds,ax
         mov  ah,[>417]
         mov  ds,cx
         and  ah,bh
         cmp  ah,bh
         jnz  if2
         mov  ax,[running]
         cmp  ax,0
         jnz  if2
         mov  [popflg],1
if2      equ  $
         mov  ax,[popflg]
         cmp  ax,0
         jz   skipex2
         les  bx,[dosbusy]
         seges
         cmp  %[bx],0
         jnz  skipex2
         mov  ax,[diskflag]
         cmp  ax,0
         jnz  skipex2
         mov  ax,[videoflag]
         cmp  ax,0
         jnz  skipex2
         mov  al,>20
         out  >20,al
         mov  [popflg],0
         call execit
skipex2  pop  es
         pop  ds
         pop  cx
         pop  bx
         pop  ax
         iret
         def execit
execit   equ $
         push ax
         push bx
         push cx
         push dx
         push si
         push di
         push ds
         push es
         push bp
         mov  ax,cs
         push ax
         call dores
         pop bp
         pop es
         pop ds
         pop di
         pop si
         pop dx
         pop cx
         pop bx
         pop ax
         ret
         def new28
new28    equ $
         push ax
         push bx
         push ds
         push es
         segcs
         mov  ax,[dgroup]
         mov  ds,ax
         pushf
         segds
         callseg [old28]
         segcs
         mov  ax,[dgroup]
         mov  ds,ax
         mov  ax,[popflg]
         cmp  ax,0
         jz   skipex3
         les  bx,[dosbusy]
         seges
         cmp  %[bx],0
         jz   skipex3
         mov  ax,[diskflag]
         cmp  ax,0
         jnz  skipex3
         mov  ax,[videoflag]
         cmp  ax,0
         jnz  skipex3
         mov  [popflg],0
         call execit
skipex3  equ  $
         pop  es
         pop  ds
         pop  bx
         pop  ax
         iret
         def newbreak
newbreak equ $
         iret
         def newcrit
newcrit  equ $
         mov ax,0
         iret
         end
